
/*


REPLICATION SYNTAX TO
*********************

Harfst, P., Wiesner, C. (2024).
Measuring political legitimacy in two dimensions: internal and external measures
Front. Polit. Sci. 6:999743.
doi: 10.3389/fpos.2024.999743

Last modified 20240124 by PH


DOWNLOAD PUBLICALLY AVAILABLE DATA SOURCES
******************************************

Download and save the following data sets and merge syntax to [YourFolder]

*** European Values Study ***
EVS Trend File 1981-2017 -- ZA7503_v3-0-0.dta
Version: 3.0.0 (2022-12-14)
Download at https://doi.org/10.4232/1.14021

*** World Values Survey ***
WVS Tred File (1981-2022) -- WVS_trends_3_0.dta
Version: v3.0.0 (2022-12-14)
Download at https://doi.org/10.14281/18241.23

*** EVS-WVS Merge Syntax (Stata) ***
EVS-WVS Merge Syntax -- EVS_WVS_Merge_Syntax_stata.do
Version V3
Download at https://doi.org/10.4232/1.14021


*** !RUN MERGE SYNTAX! ***


*** V-Dem Core ***
V-Dem Core Data Set
Version 13 (2023) -- V-Dem-CY-Core-v13.dta
Download at https://doi.org/10.23696/vdemds23


*/


*** Load IVS Data
*****************

cd "[YourFolder]"
cd "C:\Users\harfst1\Desktop\temp"


set scheme lean1
set autotabgraphs on

use Integrated_values_surveys_1981-2021.dta, clear





*** Create Trust Variables
**************************

gen conf_parl_re=E069_07
recode conf_parl_re (4=1) (3=2) (2=3) (1=4)

gen conf_gov_re=E069_11
recode conf_gov_re (4=1) (3=2) (2=3) (1=4)

gen conf_parties_re=E069_12
recode conf_parties_re (4=1) (3=2) (2=3) (1=4)

*Label Vars
label define conf 1 "None at all" 2 "Not very much" 3 "Quite a lot" 4 "A great deal", replace
local vars conf_parl_re conf_gov_re conf_parties_re
foreach v of local vars {
label values `v' conf
}

gen conf_parl_01=(conf_parl_re-1)/3
gen conf_gov_01=(conf_gov_re-1)/3
gen conf_parties_01=(conf_parties_re-1)/3


gen conf_parties_dummy=.
replace conf_parties_dummy=0 if conf_parties_re==1
replace conf_parties_dummy=0 if conf_parties_re==2
replace conf_parties_dummy=1 if conf_parties_re==3
replace conf_parties_dummy=1 if conf_parties_re==4

gen conf_parl_dummy=.
replace conf_parl_dummy=0 if conf_parl_re==1
replace conf_parl_dummy=0 if conf_parl_re==2
replace conf_parl_dummy=1 if conf_parl_re==3
replace conf_parl_dummy=1 if conf_parl_re==4

gen conf_gov_dummy=.
replace conf_gov_dummy=0 if conf_gov_re==1
replace conf_gov_dummy=0 if conf_gov_re==2
replace conf_gov_dummy=1 if conf_gov_re==3
replace conf_gov_dummy=1 if conf_gov_re==4



*** Create Fuchs/Roller (2018) "Electoral Democracy" Index
**********************************************************

*Democracy
gen demo_system_re=E117
recode demo_system_re (4=1) (3=2) (2=3) (1=4)

gen demo_leader_re=E114
recode demo_leader_re (4=1) (3=2) (2=3) (1=4)

gen demo_army_re=E116
recode demo_army_re (4=1) (3=2) (2=3) (1=4)


*Label variables "Democracy"
label define demo_01 1 "Very bad" 2 "Fairly bad" 3 "Fairly good" 4 "Very good", replace
local vars demo_system_re demo_leader_re demo_army_re
foreach v of local vars {
label values `v' demo_01
}


*Electoral Democracy
gen elec_choose=E226

gen elec_women=E233


*Label variables "Electoral Democracy"
label define demo_02 1 "Not essential characteristic of demo" 10 "Essential characteristic of demo", replace
local vars elec_choose elec_women
foreach v of local vars {
label values `v' demo_02
}


*Dichotomise variables
gen demo_system_dummy=.
replace demo_system_dummy=0 if demo_system_re==1
replace demo_system_dummy=0 if demo_system_re==2
replace demo_system_dummy=1 if demo_system_re==3
replace demo_system_dummy=1 if demo_system_re==4

gen demo_leader_dummy=.
replace demo_leader_dummy=1 if demo_leader_re==1
replace demo_leader_dummy=1 if demo_leader_re==2
replace demo_leader_dummy=0 if demo_leader_re==3
replace demo_leader_dummy=0 if demo_leader_re==4

gen demo_army_dummy=.
replace demo_army_dummy=1 if demo_army_re==1
replace demo_army_dummy=1 if demo_army_re==2
replace demo_army_dummy=0 if demo_army_re==3
replace demo_army_dummy=0 if demo_army_re==4

gen elec_choose_dummy=.
replace elec_choose_dummy=0 if elec_choose==1
replace elec_choose_dummy=0 if elec_choose==2
replace elec_choose_dummy=0 if elec_choose==3
replace elec_choose_dummy=0 if elec_choose==4
replace elec_choose_dummy=0 if elec_choose==5
replace elec_choose_dummy=0 if elec_choose==6
replace elec_choose_dummy=0 if elec_choose==7
replace elec_choose_dummy=1 if elec_choose==8
replace elec_choose_dummy=1 if elec_choose==9
replace elec_choose_dummy=1 if elec_choose==10

gen elec_women_dummy=.
replace elec_women_dummy=0 if elec_women==1
replace elec_women_dummy=0 if elec_women==2
replace elec_women_dummy=0 if elec_women==3
replace elec_women_dummy=0 if elec_women==4
replace elec_women_dummy=0 if elec_women==5
replace elec_women_dummy=0 if elec_women==6
replace elec_women_dummy=0 if elec_women==7
replace elec_women_dummy=1 if elec_women==8
replace elec_women_dummy=1 if elec_women==9
replace elec_women_dummy=1 if elec_women==10


*Create Sub-Index "Rejection Autocracy"

gen index_reject_auto=0
replace index_reject_auto=1 if demo_leader_dummy==1
replace index_reject_auto=1 if demo_army_dummy==1
replace index_reject_auto=. if demo_leader_dummy==. & demo_army_dummy==.
tab index_reject_auto, mis


*Create Sub-Index "Democracy"
gen index_demo=demo_system_dummy*index_reject_auto
tab index_demo, mis


*Create Sub-Index "Elections"
gen index_election=0
replace index_election=1 if elec_choose_dummy==1 & elec_women_dummy==1
replace index_election=. if elec_choose_dummy==. | elec_women_dummy==.
tab index_election, mis


*Create Index "Electoral Democracy"
gen index_electoral=index_demo*index_election
tab index_electoral, mis


*** REMOVE VIETNAM 2001 FROM DATA ***
*************************************

list S021 if S025==7042001
drop if S025==7042001


*** SUMMARY STATISTICS ***
**************************

***Democratic Values
tabstat index_demo index_electoral [aweight=S017], stat(mean n)
sum index_demo index_electoral

***Democratic Performance (means in dicotomous coding produce percentages)
tabstat conf_parties_dummy conf_parl_dummy conf_gov_dummy [aweight=S017], stat(mean n)
sum conf_parties_dummy conf_parl_dummy conf_gov_dummy


*** GOING TO MACRO LEVEL ***
****************************

list S024
*Russia [2017], Romania [2018] and Ukraine [2020] with two entries

*RUSSIA 2017*
*Russia surveyed twice in 2017 by WVS AND EVS
*Keep EVS only
drop if S024==6437

*ROMANIA 2018*
*Romania surveyed twice in 2018 by WVS AND EVS
*Keep EVS only
drop if S024==6427

*UKRAINE 2020*
*Ukraine surveyed twice in 2020 by WVS AND EVS
*Keep EVS only
drop if S024==8047


***Collapse Data to Country-Year Using Weights

collapse (first) COW_ALPHA COW_NUM S003 S020 S021 S025	///
(mean) mean_elec_choose=elec_choose_dummy mean_index_reject_auto=index_reject_auto mean_index_demo=index_demo mean_index_election=index_election mean_index_electoral=index_electoral mean_conf_parties_dummy=conf_parties_dummy mean_conf_parl_dummy=conf_parl_dummy mean_conf_gov_dummy=conf_gov_dummy	///
[aweight=S017], by(S024)


***Standardise Country Names and Year
kountry S003, from(iso3n) marker
tab NAMES_STD
tabulate S021 if MARKER==0

list S021 if S003==158
*Taiwan*
replace NAMES_STD="Taiwan" if S003==158

list S021 if S003==197
*Northern Cyprus*
replace NAMES_STD="Northern Cyprus" if S003==197

list S021 if S003==688
*Serbia*
replace NAMES_STD="Serbia" if S003==688

list S021 if S003==909
*Northern Ireland*
replace NAMES_STD="Northern Ireland" if S003==909

list S021 if S003==915
*Kosovo*
replace NAMES_STD="Kosovo" if S003==915

gen YEAR_STD=S020

tab YEAR_STD, mis
tab NAMES_STD, mis

sort NAMES_STD YEAR_STD

list S021 NAMES_STD YEAR_STD

sum mean_elec_choose mean_index_reject_auto mean_index_demo mean_index_election mean_index_electoral mean_conf_parties_dummy mean_conf_parl_dummy mean_conf_gov_dummy
*Electoral Democracy Index with approx 200 observations; Confidence Variables with approx 330 observations -- only "Confidence Parliament" with 398 observations



*** SAVE IVS COUNTR-YEAR DATA
*****************************

save ivs_countryyear.dta, replace


*** Load V-Dem data 
*******************

use V-Dem-CY-Core-v13.dta, replace


***Standardise Country Names and Year
kountry country_name, from(other) marker
list NAMES_STD country_name year
list NAMES_STD country_name year if MARKER==0

replace NAMES_STD="Kosovo" if NAMES_STD=="kosovo"
replace NAMES_STD="Serbia" if NAMES_STD=="Yugoslavia"
replace NAMES_STD="Czech Republic" if NAMES_STD=="czechia"
replace NAMES_STD="Macedonia" if NAMES_STD=="north macedonia"


gen YEAR_STD=year



*** MERGE V-DEM AND IVS COUNTRY-YEAR DATA
******************************************

***CLeaning up...
keep country_name country_text_id year v2x_polyarchy v2x_libdem v2x_regime NAMES_STD YEAR_STD


***Merge
merge 1:1 NAMES_STD YEAR_STD using ivs_countryyear.dta

sort NAMES_STD YEAR_STD
list NAMES_STD YEAR_STD if _merge==2

drop _merge


***Cleaning up

drop if S003==.
drop if v2x_polyarchy==.

sort NAMES_STD YEAR_STD
gen n=_n


***Generate variable combining country abbreviation and year

tostring year, generate(year_txt)
egen c_y_txt = concat(country_text_id year_txt)
list c_y_txt


***Generate variable to distinguish democracies from autocracies

gen demo=0
replace demo=1 if v2x_polyarchy>=.5
list c_y_txt if v2x_polyarchy==.


sort NAMES_STD YEAR_STD
list NAMES_STD YEAR_STD v2x_polyarchy if demo==0
list NAMES_STD YEAR_STD v2x_polyarchy if demo==1


*** MACRO LEVEL ANALYSES
************************


***Figures 1 to 4

twoway scatter mean_index_electoral v2x_polyarchy, mlabel(c_y_txt) mlabsize(vsmall) ms(none) xline(.5, lpattern(longdash) lcolor(gray)) yline(.5, lpattern(longdash) lcolor(gray)) ytitle("Internal Legitimacy Dimension" "Electoral Democratic Values (IVS)") xtitle("External Legitimacy Dimension" "Index Electoral Democracy (V-Dem)") name(value, replace)

twoway scatter mean_conf_parties_dummy v2x_polyarchy, mlabel(c_y_txt) mlabsize(vsmall) ms(none) xline(.5, lpattern(longdash) lcolor(gray)) yline(.5, lpattern(longdash) lcolor(gray)) ytitle("Internal Legitimacy Dimension" "Trust in Parties (IVS)") xtitle("External Legitimacy Dimension" "Index Electoral Democracy (V-Dem)") name(parties, replace)

twoway scatter mean_conf_parl_dummy v2x_polyarchy, mlabel(c_y_txt) mlabsize(vsmall) ms(none) xline(.5, lpattern(longdash) lcolor(gray)) yline(.5, lpattern(longdash) lcolor(gray)) ytitle("Internal Legitimacy Dimension" "Trust in Parliament (IVS)") xtitle("External Legitimacy Dimension" "Index Electoral Democracy (V-Dem)") name(parl, replace)

twoway scatter mean_conf_gov_dummy v2x_polyarchy, mlabel(c_y_txt) mlabsize(vsmall) ms(none) xline(.5, lpattern(longdash) lcolor(gray)) yline(.5, lpattern(longdash) lcolor(gray)) ytitle("Internal Legitimacy Dimension" "Trust in Government (IVS)") xtitle("External Legitimacy Dimension" "Index Electoral Democracy (V-Dem)") name(gov, replace)


***TABLE 2: Specific and diffuse support in democratic and autocratic states (shares)

*Democratic countries only
sum mean_index_electoral if demo==1
sum mean_conf_parties_dummy if demo==1
sum mean_conf_parl_dummy if demo==1
sum mean_conf_gov_dummy if demo==1

*Non-democratic countries only
sum mean_index_electoral if demo==0
sum mean_conf_parties_dummy if demo==0
sum mean_conf_parl_dummy if demo==0
sum mean_conf_gov_dummy if demo==0


***TABLE 3: Relationships between internal and external dimensions of political legitimacy

*Full sample
regress v2x_polyarchy mean_index_electoral
regress v2x_polyarchy mean_conf_parties_dummy
regress v2x_polyarchy mean_conf_parl_dummy
regress v2x_polyarchy mean_conf_gov_dummy


*Democratic countries only
regress v2x_polyarchy mean_index_electoral if demo==1
regress v2x_polyarchy mean_conf_parties_dummy if demo==1
regress v2x_polyarchy mean_conf_parl_dummy if demo==1
regress v2x_polyarchy mean_conf_gov_dummy if demo==1


*Non-democratic countries only
regress v2x_polyarchy mean_index_electoral if demo==0
regress v2x_polyarchy mean_conf_parties_dummy if demo==0
regress v2x_polyarchy mean_conf_parl_dummy if demo==0
regress v2x_polyarchy mean_conf_gov_dummy if demo==0


***TABLE 4: Classification of cases in two ideal types of hybrid regimes
*(List countries in tyo hybrid categories of legitimacy)
*(Calculate shares by hand)

*...Subjective Legitimacy...*

*...Democratic Values
list country_name year if mean_index_electoral>=.5 & mean_index_electoral!=. & v2x_polyarchy<.5 & v2x_polyarchy!=.
tab c_y_txt if mean_index_electoral>=.5 & mean_index_electoral!=. & v2x_polyarchy<.5 & v2x_polyarchy!=.

*...Trust Parties
list country_name year if mean_conf_parties_dummy>=.5 & mean_conf_parties_dummy!=. & v2x_polyarchy<.5 & v2x_polyarchy!=.
tab c_y_txt if mean_conf_parties_dummy>=.5 & mean_conf_parties_dummy!=. & v2x_polyarchy<.5 & v2x_polyarchy!=.

*...Trust Parliament
list country_name year if mean_conf_parl_dummy>=.5 & mean_conf_parl_dummy!=. & v2x_polyarchy<.5 & v2x_polyarchy!=.
tab c_y_txt if mean_conf_parl_dummy>=.5 & mean_conf_parl_dummy!=. & v2x_polyarchy<.5 & v2x_polyarchy!=.

*...Trust Government
list country_name year if mean_conf_gov_dummy>=.5 & mean_conf_gov_dummy!=. & v2x_polyarchy<.5 & v2x_polyarchy!=.
tab c_y_txt if mean_conf_gov_dummy>=.5 & mean_conf_gov_dummy!=. & v2x_polyarchy<.5 & v2x_polyarchy!=.


*...Formal Legitimacy...*

*...Democratic Values
list country_name year if mean_index_electoral<.5 & mean_index_electoral!=. & v2x_polyarchy>=.5 & v2x_polyarchy!=.
tab c_y_txt if mean_index_electoral<.5 & mean_index_electoral!=. & v2x_polyarchy>=.5 & v2x_polyarchy!=.

*...Trust Parties
list country_name year if mean_conf_parties_dummy<.5 & mean_conf_parties_dummy!=. & v2x_polyarchy>=.5 & v2x_polyarchy!=.
tab c_y_txt if mean_conf_parties_dummy<.5 & mean_conf_parties_dummy!=. & v2x_polyarchy>=.5 & v2x_polyarchy!=.

*...Trust Parliament
list country_name year if mean_conf_parl_dummy<.5 & mean_conf_parl_dummy!=. & v2x_polyarchy>=.5 & v2x_polyarchy!=.
tab c_y_txt if mean_conf_parl_dummy<.5 & mean_conf_parl_dummy!=. & v2x_polyarchy>=.5 & v2x_polyarchy!=.

*...Trust Government
list country_name year if mean_conf_gov_dummy<.5 & mean_conf_gov_dummy!=. & v2x_polyarchy>=.5 & v2x_polyarchy!=.
tab c_y_txt if mean_conf_gov_dummy<.5 & mean_conf_gov_dummy!=. & v2x_polyarchy>=.5 & v2x_polyarchy!=.


*...Total Number of Cases...*

*...Democratic Values
list country_name year if mean_index_electoral!=. & v2x_polyarchy!=.
tab c_y_txt if mean_index_electoral!=. & v2x_polyarchy!=.

*...Trust Parties
list country_name year if mean_conf_parties_dummy!=. & v2x_polyarchy!=.
tab c_y_txt if mean_conf_parties_dummy!=. & v2x_polyarchy!=.

*...Trust Parliament
list country_name year if mean_conf_parl_dummy!=. & v2x_polyarchy!=.
tab c_y_txt if mean_conf_parl_dummy!=. & v2x_polyarchy!=.

*...Trust Government
list country_name year if mean_conf_gov_dummy!=. & v2x_polyarchy!=.
tab c_y_txt if mean_conf_gov_dummy!=. & v2x_polyarchy!=.


***Cases that fall into all ambiguous categories

*Formal legitimacy

list country_name year if mean_index_electoral<.5 & mean_index_electoral!=. & mean_conf_parties_dummy<.5 & mean_conf_parties_dummy!=. & mean_conf_parl_dummy<.5 & mean_conf_parl_dummy!=. & mean_conf_gov_dummy<.5 & mean_conf_gov_dummy!=. & v2x_polyarchy>=.5 & v2x_polyarchy!=.

*Subjective legitimacy

list country_name year if mean_index_electoral>=.5 & mean_index_electoral!=. & mean_conf_parties_dummy>=.5 & mean_conf_parties_dummy!=. &mean_conf_parl_dummy>=.5 & mean_conf_parl_dummy!=. & mean_conf_gov_dummy>=.5 & mean_conf_gov_dummy!=. & v2x_polyarchy<.5 & v2x_polyarchy!=.


*** EXPORT GRAPHS FOR PUBLICATION
*********************************

graph display value
graph export figure_01.svg, replace
graph export figure_01.tif, replace

graph display parties
graph export figure_02.svg, replace
graph export figure_02.tif, replace

graph display parl
graph export figure_03.svg, replace
graph export figure_03.tif, replace

graph display gov
graph export figure_04.svg, replace
graph export figure_04.tif, replace
